<template>
  <div class="hospitalsign">
    <div class="top">
      <div class="title">门诊就诊信息</div>
      <div class="topinfo">
        <div class="post">就诊医院</div>
        <div>
           <input
            type="text"
            placeholder="请输入就诊医院"
            v-model="form.hospitalName"
          />
        </div>
      </div>
      <div class="topinfo" @click="showDatePicker('startDate')">
        <div class="post">就诊时间</div>
        <div style="padding-left:10px" :style="form.date ? '' : 'color:#ccc;'">
          {{form.date | dateFormat('请选择')}}
        </div>
      </div>
      <div class="topinfo">
        <div class="post">诊断情况</div>
        <div>
          <input
            type="text"
            placeholder="请输入诊断情况"
            v-model="form.diagnosis"
          />
        </div>
      </div>
      <div class="topinfo">
        <div class="post">治疗情况</div>
        <div>
          <input
            type="text"
            placeholder="请输入治疗情况"
            v-model="form.treatment"
          />
        </div>
      </div>
      <div class="topinfo">
        <div class="post">自费金额</div>
        <div>
          <input
            type="text"
            placeholder="请输入自费金额"
            v-model="form.feeBySelf"
          />
        </div>
      </div>
      <!-- <div class="topinfo">
                <div class="post special">是否需要支票（2-10万）</div>
                <div class="arrow" @click="showPicker('needzp')">
                    <p :style="{'color': needzp?'#333333' :'#cccccc'}">{{needzp ? needzp : '请选择'}}</p>
                    <van-icon name="arrow" />
                </div>
            </div> -->
    </div>
    <div class="sign-btn" @click="submit">提交</div>
    <div class="historylist">
      <p class="historytitle">历次申请记录</p>
      <div class="item" v-for="(item, i) in list" :key="i" @click="getDetail(item)">
        <div>
          <p>就医日期：{{ item.jzsj }}</p>
          <p>{{ item.jzyy }}</p>
        </div>
        <div><van-icon name="arrow" /></div>
      </div>
    </div>
    <date-picker
      @fetchData="fetchDate"
      date-type="date"
      :default-date="form.date"
      :show="isDatePickerShow"
      @cancel="hideDatePicker"
      @hide="hideDatePicker"
    ></date-picker>
  </div>
</template>

<script>
import datePicker from '../components/datePicker';
import moment from 'moment';
import {mzdjsavedata, mzdjquerydata4list, mzdjquerydata4object} from '../assets/js/api';
export default {
  filters: {
    dateFormat(v, defaultValue) {
      return (v && moment(v).format('YYYY-MM-DD')) || defaultValue;
    }
  },
  data() {
    return {
      isDatePickerShow: false,
      form: {
        hospitalName: '',
        date: '',
        diagnosis: '',
        treatment: '',
        feeBySelf: ''
      },
      show: false,
      pickerOptions: {
        pickerColumns: []
      },
      list: [],
      dspToken: localStorage.dspToken
    };
  },
  components: {
    datePicker
  },
  mounted() {
    this.mzdjquerydata4list();
  },
  methods: {
    mzdjquerydata4list() {
      mzdjquerydata4list({
        dspToken: this.dspToken
      }).then(res => {
        this.list = res.data;
      });
    },
    getDetail(d) {
      mzdjquerydata4object({
        jzxxId: d.jzxxId,
        dspToken: this.dspToken
      }).then(({data}) => {
        console.log(data);
        const x = data[0];
        this.$router.push({
          name: 'detail',
          query: {
            title: '门诊就诊详情',
            data: JSON.stringify({
              '就诊医院': x.jzyy,
              '就诊时间': x.jzsj,
              '诊断情况': x.zdqk,
              '治疗情况': x.zlqk,
              '自费金额': x.zfje
            })
          }
        });
      });
    },
    showDatePicker(type) {
      this.isDatePickerShow = true;
    },
    fetchDate(d) {
      this.form.date = d.originValue;
      this.isDatePickerShow = d.showDatePicker;
    },
    hideDatePicker(d) {
      this.isDatePickerShow = d.showDatePicker;
    },
    submit() {
      if (!this.form.hospitalName) {
        return this.$toast('请填写就诊医院');
      }
      if (!this.form.date) {
        return this.$toast('请选择就诊日期');
      }
      if (!this.form.diagnosis) {
        return this.$toast('请输入诊断情况');
      }
      if (!this.form.treatment) {
        return this.$toast('请输入治疗情况');
      }
      if (!this.form.feeBySelf) {
        return this.$toast('请输入自费金额');
      }
      mzdjsavedata({
        jzyy: this.form.hospitalName,
        jzsj: moment(this.form.date).format('YYYY-MM-DD'),
        zdqk: this.form.diagnosis,
        zlqk: this.form.treatment,
        zfje: this.form.feeBySelf,
        dspToken: this.dspToken
      }).then(res => {
        this.$toast('提交成功');
        this.mzdjquerydata4list();
        this.form = {
          hospitalName: '',
          date: '',
          diagnosis: '',
          treatment: '',
          feeBySelf: ''
        };
      });
    }
  }
};
</script>

<style lang="less" scoped>
.hospitalsign {
  padding: 24px;
  .top {
    width: 704px;
    background-color: #ffffff;
    box-shadow: 3px 4px 9px 1px rgba(1, 88, 155, 0.05);
    border-radius: 8px;
    margin: 0 auto;
    .title {
      height: 64px;
      background-color: #3198ed;
      color: #ffffff;
      font-size: 30px;
      line-height: 64px;
      padding: 0 16px;
      border-top-left-radius: 8px;
      border-top-right-radius: 8px;
    }
    .topinfo {
      display: flex;
      padding: 35px 18px;
      box-sizing: border-box;
      width: 674px;
      margin: 0 auto;
      font-size: 34px;
      color: #343434;
      &:not(:last-child) {
        border-bottom: 1px solid #eeeeee;
      }
      .post {
        color: #888888;
        text-align: left;
        width: 220px;
      }
      div:last-child {
        flex: 1;
        text-align: right;
        input {
          text-align: right;
        }
      }
      .special {
        width: 380px;
      }
      .arrow {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        font-size: 34px;
        color: #888;
        text-align: right;
      }
    }
  }
  .sign-btn {
    border: none;
    width: 704px;
    height: 90px;
    background-color: #3198ed;
    box-shadow: 0px 5px 5px 0px rgba(89, 166, 250, 0.1);
    border-radius: 45px;
    line-height: 90px;
    color: #ffffff;
    font-size: 36px;
    text-align: center;
    margin: 26px auto;
    letter-spacing: 7px;
  }
  .historylist {
    .historytitle {
      color: #888888;
      font-size: 30px;
      margin: 19px 0;
    }
    .item {
      width: 704px;
      // height: 140px;
      padding: 36px 0;
      background-color: #ffffff;
      box-shadow: 3px 4px 9px 1px rgba(1, 88, 155, 0.05);
      border-radius: 8px;
      margin: 0 auto;
      margin-top: 23px;
      position: relative;
      padding: 31px 30px 26px 33px;
      box-sizing: border-box;
      display: flex;
      &::before {
        content: "";
        width: 5px;
        // height: 140px;
        background-color: #3198ed;
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        border-top-left-radius: 50px;
        border-bottom-left-radius: 50px;
      }
      > div:first-child {
        flex: 1;
        p:first-child {
          color: #888888;
          font-size: 30px;
        }
        p:last-child {
          width: calc(100vw - 160px);
          color: #353535;
          font-size: 34px;
          // white-space: nowrap;
          // text-overflow: ellipsis;
          // overflow: hidden;
        }
      }
      > div:last-child {
        width: 50px;
        font-size: 34px;
        color: #b2b2b2;
        align-self: center;
        text-align: right;
      }
    }
  }
}
</style>
